package com.sx.export.Threads;

import com.alibaba.excel.EasyExcel;
import com.sx.export.Utils.CustomCellWriteWidthConfig;
import com.sx.export.domain.po.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.concurrent.Callable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExportExcelThread implements Callable<Boolean> {

    private List<User> users;
    private String fileName;
    private int count = 0;

    @Override
    public Boolean call() throws Exception {

        try {
            EasyExcel.write(fileName, User.class).sheet(0).registerWriteHandler(new CustomCellWriteWidthConfig()).doWrite(users);
        }catch (Exception e){
            if (count < 3 ){
                call();
            }else {
                return false;
            }

        }
        return true;
    }
}
